home *** CD-ROM | disk | FTP | other *** search
- { button.pas -- Buttons in dialogs }
-
- program Button;
-
- {$R button.res}
-
- uses WinTypes, WinProcs, WObjects, ButtonU;
-
- const
-
- id_Menu = 100; { Menu resource ID }
- cm_Dialog = 101; { Dialog-command ID }
- id_Dialog = 200; { Dialog resource ID }
-
- id_cb1 = 101; { Check box IDs }
- id_cb2 = 102;
- id_cb3 = 103;
- id_rb1 = 104; { First group of radio button IDs }
- id_rb2 = 105;
- id_rb3 = 106;
- id_rb4 = 107; { Second group of radio button IDs }
- id_rb5 = 108;
- id_rb6 = 109;
-
- type
-
- PDialogRec = ^DialogRec; { Pointer to DialogRec record }
- DialogRec = record
- Checks: CBSet; { Check box bit set }
- RadiosG1: RadioSet; { Radio buttons -- Group 1 }
- RadiosG2: RadioSet; { Radio buttons -- Group 2 }
- end;
-
- PBDialog = ^BDialog;
- BDialog = object(TDialog)
- DataPointer: PDialogRec;
- constructor Init(AParent: PWindowsObject; AName: PChar;
- P: PDialogRec);
- procedure SetupWindow; virtual;
- procedure IDCB1(var Msg: TMessage);
- virtual id_First + id_cb1;
- procedure Ok(var Msg: TMessage);
- virtual id_First + id_Ok;
- end;
-
- DButtonApplication = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
- PDButtonWindow = ^DButtonWindow;
- DButtonWindow = object(TWindow)
- DialogData: DialogRec;
- constructor Init(AParent: PWindowsObject; ATitle: PChar);
- procedure CMDialog(var Msg: TMessage);
- virtual cm_First + cm_Dialog;
- end;
-
-
- { BDialog }
-
- {- Construct BDialog instance. P addresses dialog data record. }
- constructor BDialog.Init(AParent: PWindowsObject; AName: PChar;
- P: PDialogRec);
- begin
- TDialog.Init(AParent, AName);
- DataPointer := P { Save pointer to caller's dialog record }
- end;
-
- {- Prepare initial control values }
- procedure BDialog.SetupWindow;
- var
- I: Integer;
- begin
- TDialog.SetUpWindow;
- with DataPointer^ do
- begin
- SetChecks(HWindow, Checks, id_cb1, id_cb3);
- SetRadios(HWindow, RadiosG1, id_rb1, id_rb3);
- SetRadios(HWindow, RadiosG2, id_rb4, id_rb6)
- end
- end;
-
- {- Demonstrate interactive response to button activity }
- procedure BDialog.IDCB1(var Msg: TMessage);
- begin
- MessageBeep(0) { First check box beeps when selected }
- end;
-
- {- Respond to Ok button }
- procedure BDialog.Ok(var Msg: TMessage);
- begin
- with DataPointer^ do
- begin
- GetChecks(HWindow, Checks, id_cb1, id_cb3);
- GetChecks(HWindow, RadiosG1, id_rb1, id_rb3);
- GetChecks(HWindow, RadiosG2, id_rb4, id_rb6)
- end;
- TDialog.Ok(Msg)
- end;
-
-
- { DButtonApplication }
-
- {- Initialize DButtonApplication object's window }
- procedure DButtonApplication.InitMainWindow;
- begin
- MainWindow := New(PDButtonWindow, Init(nil, 'Button'))
- end;
-
-
- { DButtonWindow }
-
- {- Construct DButtonWindow object; Initialize dialog data record }
- constructor DButtonWindow.Init(AParent: PWindowsObject;
- ATitle: PChar);
- begin
- TWindow.Init(AParent, ATitle);
- Attr.Menu := LoadMenu(HInstance, PChar(id_Menu));
- with DialogData do
- begin
- Checks := [0, 2]; { Set 1st and 3rd check boxes }
- RadiosG1 := [1]; { Set 2nd radio button in first group }
- RadiosG2 := [0] { Set 1st radio button in second group }
- end;
- end;
-
- {- Execute Menu:Dialog command }
- procedure DButtonWindow.CMDialog(var Msg: TMessage);
- begin
- Application^.ExecDialog(New(PBDialog,
- Init(@Self, PChar(id_Dialog), @DialogData)))
- end;
-
- var
-
- DButtonApp: DButtonApplication;
-
- begin
- DButtonApp.Init('DButtonApp');
- DButtonApp.Run;
- DButtonApp.Done
- end.
-
-
- {--------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 3/19/1991
- ---------------------------------------------------------------}
-